const HtmlWebpackPlugin = require("html-webpack-plugin")
const path = require("path")
const terserPlugin = require("terser-webpack-plugin")
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
module.exports = {
    mode: 'development',
    entry: "./src/index.js",
    devtool:"inline-source-map",
    output: {
        filename: "[name].[contenthash].js",
        path: path.resolve(__dirname, "dist")
    },
    resolve:{
        alias:{
            "@" : path.resolve(__dirname,'src')
        }
    },
    plugins:[
        new HtmlWebpackPlugin({
        title:"博客列表" 
    }),
    new BundleAnalyzerPlugin.BundleAnalyzerPlugin()
],

    optimization:{
        minimize:true,
        minimizer:[new terserPlugin()]
    },
    devServer:{
        static:"./dist"
    },
    module: {
        rules: [
            {
                test: /\.css$/i,
                use: ["style-loader", "css-loader"],
            },
            {
                test:/\.(png|svg|jpeg|jpg|gif)$/i,
                type:"asset/resource"
            },
            {
                test:/\.js$/,
                exclude:/node_modules/,
                use:{
                    loader:"babel-loader",
                    options:{
                        presets:["@babel/preset-env"],
                    }
                }
            }
        ]
    }
}